package cn.bestick.weightrecord.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Created by IntelliJ IDEA.
 * User: Bestick
 * Date: 2016/7/8
 * Time: 15:22
 * Url: http://www.bestick.cn
 * Copyright © 2015-2016 Bestick All rights reserved
 * -----------------------------------------------------------
 * 会当凌绝顶，一览众山小。
 */
@Controller
public class PageController {

    /**
     * 主页接口
     *
     * @param session HttpSession
     * @return 已登录返回home，未登录返回login
     */
    @RequestMapping("/index")
    public String index(HttpSession session) {
        if (session.getAttribute("currentUser") == null) {
            return "login";
        }
        return "home";
    }

    /**
     * home页接口
     *
     * @param session HttpSession
     * @param request HttpServletRequest
     * @return 已登录返回home，未登录返回login
     */
    @RequestMapping(value = "/home")
    public String home(HttpSession session, HttpServletRequest request) {
        if (session.getAttribute("currentUser") == null) {
            request.setAttribute("msg", "亲，请先登录哦");
            return "login";
        }
        return "home";
    }

    /**
     * 针对IE10版本一下浏览器进行拦截
     * @return updateBrowser
     */
    @RequestMapping(value = "/updateBrowser")
    public String updateBrowser() {
        return "updateBrowser";
    }

    /**
     * 注册页面请求接口
     * @return signup
     */
    @RequestMapping(value = "/signup")
    public String signUp() {
        return "signup";
    }
}